package com.gaogzhen.security.intro;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "security.intro.ThreadSecurity01")
public class ThreadSecurity01 {
    static int n = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                n++;
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                n--;
            }
        }, "t2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        log.debug("最终结果：{}", n);
    }
}
